package com.ljy.controller.user;

import com.ljy.dto.LeaseOrdersDTO;
import com.ljy.dto.OrdersPaymentDTO;
import com.ljy.entity.LeaseOrders;
import com.ljy.result.Result;
import com.ljy.service.LeaseOrdersService;
import com.ljy.vo.LeaseOrdersDetailVO;
import com.ljy.vo.LeaseOrdersSubmitVO;
import com.ljy.vo.LeaseOrdersVO;
import com.ljy.vo.OrdersPaymentVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userLeaseOrdersController")
@RequestMapping("/user/leaseOrder")
@Slf4j
public class LeaseOrdersController {
    @Autowired
    LeaseOrdersService leaseOrdersService;
    @PostMapping("/submit")
    public Result<LeaseOrdersSubmitVO> submit(@RequestBody LeaseOrdersDTO dto){
        LeaseOrdersSubmitVO leaseOrdersVO = leaseOrdersService.submit(dto);
        return Result.success(leaseOrdersVO);
    }
    @GetMapping
    public Result<List<LeaseOrdersVO>> list(){
        List<LeaseOrdersVO> list = leaseOrdersService.list();
        return Result.success(list);
    }
    @GetMapping("/{id}")
    public Result<LeaseOrders> getOrderById(@PathVariable Integer id){
        LeaseOrders leaseOrders = leaseOrdersService.getOrdersById(id);
        return Result.success(leaseOrders);
    }

    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    public Result<OrdersPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrdersPaymentVO orderPaymentVO = leaseOrdersService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }
}
